package com.bentley.kotlindemo.ui.kits.authorlist

import android.os.Bundle
import android.util.Log
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.bentley.kotlindemo.R
import com.bentley.kotlindemo.base.BaseActivity
import com.bentley.kotlindemo.databinding.ActivityAuthorlistBinding
import com.bentley.kotlindemo.net.RespStatus
import com.bentley.kotlindemo.ui.kits.authorlist.adapter.AuthorListAdapter

/**
 * <pre>
 *  ┌────────────────────────────────────────────
 *  │ @author  Lee  @date 2021/3/17 09:36
 *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
 *  │ @desc
 *  └────────────────────────────────────────────
 * </pre>
 */
class AuthorListActivity : BaseActivity<ActivityAuthorlistBinding, AuthorListViewModel>() {

    private fun setupObservers() {
        viewModel.getUsers().observe(this, Observer {
            it?.let { resource ->
                when (resource.status) {
                    RespStatus.SUCCESS -> {
                        var adapter =
                            AuthorListAdapter(R.layout.item_authorlist, it.data?.toMutableList())
                        adapter.setOnItemClickListener { adapter, view, position ->
                            Log.d("auth", "点击1+" + position)
                        }
                        dataBinding?.recyclerView?.layoutManager = LinearLayoutManager(this)
                        dataBinding?.recyclerView?.adapter = adapter
                        dismissLoadingDialog()
                    }
                    RespStatus.ERROR -> dismissLoadingDialog()
                    RespStatus.LOADING -> showLoadingDialog()

                }

            }
        })

    }

    override fun initView(savedInstanceState: Bundle?) {
        setupObservers()
    }

    override fun getLayoutId() = R.layout.activity_authorlist
}